/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : 
  * Description        : 
  ******************************************************************************
  * @attention
  *
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "Vofa.h"
#include "string.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

typedef struct  {
    float fdata[CH_COUNT];
    unsigned char tail[4];
}_Frame;


/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
_Frame Frame;
uint8_t tempData[CH_COUNT*4];
static uint8_t COUNT;
/* USER CODE END Variables */

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
void VofaData_Config(uint8_t ch_count)
{
	//frame tail constant
	Frame.tail[0] = 0x00;
	Frame.tail[1] = 0x00;
	Frame.tail[2] = 0x80;
	Frame.tail[3] = 0x7F;
	
	for(int i = 0; i < CH_COUNT - 1;i++)
	{
		Frame.fdata[i] = 0.0;
	}
	
	COUNT = ch_count;
	
	LL_DMA_DisableChannel(DMA1,LL_DMA_CHANNEL_2);
	LL_DMA_SetMemoryAddress(DMA1, LL_DMA_CHANNEL_2, (uint32_t)(USART2_TX_BUFFER));
	LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_2, (ch_count*4 + 4));
	LL_DMA_EnableChannel(DMA1,LL_DMA_CHANNEL_2);
}

/**
  * @brief  
  * @note   
  * @param  
  * @retval 
  */
void VofaData_Update(uint8_t ch,float value)
{
	Frame.fdata[ch] = value;
}
/**
  * @brief  
  * @note   
  * @param  
  * @retval 
  */
void VofaData_Send(void)
{
	memcpy(USART2_TX_BUFFER,(uint8_t *)&Frame.fdata,sizeof(Frame.fdata));
	if(COUNT > CH_COUNT)COUNT = CH_COUNT;
	//if(COUNT < 1)return;
	for(int i = (COUNT * 4) ;i < (COUNT*4 + 4) ; i++)
	{
		USART2_TX_BUFFER[i] = Frame.tail[i - ((COUNT * 4))];
	}
	
}


/* USER CODE END Application */

